<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>

</body>

</html>
<script>
    function confirm(flag) {
        return new Promise((resolve, reject) => {
            if (flag == 1) {
                return resolve({
                    code: 200,
                    msg: '请求数据成功'
                })
            } else if (flag == 2) {
                return reject({
                    code: 500,
                    msg: '衣服穿少点',
                })
            }
        })
    }
    confirm(1).then(res => {
        console.log(res)
    }).catch(err => {
        console.log(err)
    })
    confirm(2).then(res => {
        console.log(res)
    }).catch(err => {
        console.log(err)
    })
</script>